

package gui;

import java.io.IOException;
import java.util.InvalidPropertiesFormatException;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;


public class TraductionPref {
    private static TraductionPref instance = new TraductionPref();

    static float getprefFloat(String string, float epdef) {
        return instance.pref.getFloat(string, epdef);
    }
    private Properties propLg = new Properties();
    private Preferences pref;
    private Properties propLgsDispo = new Properties();

    private TraductionPref(){
        pref = Preferences.userNodeForPackage(getClass());
        try {
            propLg.loadFromXML(getClass().getResourceAsStream("config/" + pref.get("lang", "lgFra.xml")));
        } catch (Exception ex) {
            try {
                propLg.loadFromXML(getClass().getResourceAsStream("config/lgFra.xml"));
            } catch (Exception ex1) {
                Logger.getLogger(TraductionPref.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }
        try {
            propLg.loadFromXML(getClass().getResourceAsStream("config/" + pref.get("lang", "lgFra.xml")));
        } catch (Exception ex) {
            try {
                propLg.loadFromXML(getClass().getResourceAsStream("config/lgFra.xml"));
            } catch (Exception ex1) {
                Logger.getLogger(TraductionPref.class.getName()).log(Level.SEVERE, null, ex1);
            }
        }
        try {
            propLgsDispo.loadFromXML(getClass().getResourceAsStream("config/langDispo.xml"));
        } catch (Exception ex) {
            Logger.getLogger(TraductionPref.class.getName()).log(Level.SEVERE, null, ex);
        }

    }


    static String getprefStr(String key, String def){
        return instance.pref.get(key, def);
    }
    static void putPrefFloat(String key, Float value){
        instance.pref.putFloat(key, value);
    }
    static void putPrefStr(String key, String value){
        instance.pref.put(key, value);
    }
    static Set<String> getLgsDispo(){
        return instance.propLgsDispo.stringPropertyNames();
    }
    static void putLgDef(String key){
        instance.pref.put("lang", instance.propLgsDispo.getProperty(key, "lgFra.xml"));
    }
    static String getMSG(String key){
        return instance.propLg.getProperty(key);
    }
}
